package com.circ2disease.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.circ2disease.mapper.mybatis.CircRNAMapper;
import com.circ2disease.pojo.CircRNA;
import com.circ2disease.pojo.CircRNA_table;
import com.circ2disease.pojo.Disease;
import com.circ2disease.pojo.RelationEneity;
import com.circ2disease.service.CircRNAService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

@Service
public class CircRNAServiceimpl implements CircRNAService{


    @Autowired
    CircRNAMapper mapper;

    @Override
    public Integer addCircRNA(CircRNA circRNA) {
        return mapper.addCircRNA(circRNA);
    }

    @Override
    public Integer addTable(CircRNA_table circTable) {
        return mapper.addTable(circTable);
    }

    @Override
    public Integer addAlias(Integer rnaid, String aliasName) {
        return mapper.addAlias(rnaid,aliasName);
    }

    @Override
    public IPage<CircRNA_table> listsimpleTable(Integer current, Integer size) {

        Page<CircRNA_table> circRNA_tablePage = new Page<>(current, size);
        return mapper.listsimpleTable(circRNA_tablePage);
    }

    @Override
    public IPage<CircRNA_table> listTable(Integer current, Integer size) {
        Page<CircRNA_table> circRNA_tablePage = new Page<>(current, size);
        return mapper.listTable(circRNA_tablePage);
    }

    @Override
    public IPage<Disease> listDisease(Integer current, Integer size) {
        Page<Disease> diseasePage = new Page<>(current, size);
        return mapper.listDisease(diseasePage);
    }

    @Override
    public IPage<CircRNA> listCircRNA(Integer current, Integer size) {

        Page<CircRNA> circRNAPage = new Page<>(current, size);
        return mapper.listCircRNA(circRNAPage);
    }

    @Override
    public String getRNANameById(Integer id) {
        return mapper.getRNANameById(id);
    }

    @Override
    public Integer getRNAidByName(String aliasName) {
        return mapper.getRNAidByName(aliasName);
    }

    @Override
    public IPage<CircRNA_table> getTableByRNAName(String RNAName, Integer current, Integer size) {

        Integer RNAid = mapper.getRNAidByName(RNAName);
        Page<CircRNA_table> circRNA_tablePage = new Page<>(current,size);


        return mapper.getTableByid(circRNA_tablePage,RNAid);
    }

    @Override
    public IPage<CircRNA_table> getSimpleTableByrnaName(String rnaName, Integer current, Integer size) {
        Integer RNAid = mapper.getRNAidByName(rnaName);
        Page<CircRNA_table> circRNA_tablePage = new Page<>(current,size);
        return mapper.getSimpleTableByrnaid(circRNA_tablePage,RNAid);
    }

    @Override
    public IPage<CircRNA_table> getTableByid(Integer id, Integer current, Integer size) {

        Page<CircRNA_table> circRNA_tablePage = new Page<>(current, size);

        return mapper.getTableByid(circRNA_tablePage,id);


    }

    @Override
    public IPage<CircRNA_table> getSimpleTableByrnaid(Integer id, Integer current, Integer size) {
        Page<CircRNA_table> circRNA_tablePage = new Page<>(current,size);
        return mapper.getSimpleTableByrnaid(circRNA_tablePage,id);

    }

    @Override
    public IPage<CircRNA_table> getTableByDisease(String diseaseName, Integer current, Integer size) {
        Page<CircRNA_table> circRNA_tablePage = new Page<>(current, size);
        Disease disease = new Disease();
        disease.setDiseaseName(diseaseName);
        return mapper.getTableByDisease(circRNA_tablePage,disease);
    }

    @Override
    public IPage<CircRNA_table> getSimpleTableByDisease(String diseaseName, Integer current, Integer size) {
        Page<CircRNA_table> circRNA_tablePage = new Page<>(current, size);
        Disease disease = new Disease();
        disease.setDiseaseName(diseaseName);
        return mapper.getSimpleTableByDisease(circRNA_tablePage,disease);
    }

    @Override
    public CircRNA_table getTableByRNAandDisease(String rnaName, String diseaseName) {

       return mapper.getByCircRNANameAndDiseaseName(rnaName, diseaseName);
    }

    @Override
    public CircRNA_table getTableByTableId(Integer Tableid) {
        return mapper.getTableByTableId(Tableid);
    }

    @Override
    public List<RelationEneity> listRelationEneity() {
        return mapper.listRelationEneity();
    }

    @Override
    public Set<RelationEneity> listRelationEneitybyName(List<String> rnaName, List<String> diseaseName) {
        HashSet<RelationEneity> relationEneities = new HashSet<>();
        if(rnaName.size()==0&&diseaseName.size()==0){
            return relationEneities;
        }
        for (String s : rnaName) {
            relationEneities.addAll(mapper.listRelationEneityByRna(s));
        }
        for (String s : diseaseName) {
            relationEneities.addAll(mapper.listRelationEneityByDisease(s));
        }
        return relationEneities;





    }


}
